#!/bin/bash

# 检查输入参数是否足够
if [[ $# -lt 2 ]]; then
    echo "错误：请输入两个参数。"
    echo "用法：$0 <cc> <number>"
    exit 1
fi

# 获取输入的参数
cc=$1
number=$2

# 回显即将执行的命令
echo "即将执行以下命令："
echo "nohup ./waf --run \"scratch/third input/config_${cc}_30.txt 30_${number}\" > log/run_${cc}_30_${number}.log &"
echo "nohup ./waf --run \"scratch/third input/config_${cc}_60.txt 60_${number}\" > log/run_${cc}_60_${number}.log &"
echo "nohup ./waf --run \"scratch/third input/config_${cc}_90.txt 90_${number}\" > log/run_${cc}_90_${number}.log &"

# 确认是否执行命令
read -p "确认执行以上命令吗? (y/n): " confirm
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
    echo "取消执行。"
    exit 0
fi

# 执行命令
echo "Building"
./waf build > /dev/null 2>&1
sleep 2
echo "Building Finished."
nohup ./waf --run "scratch/third input/config_${cc}_30.txt 30_${number}" > log/run_${cc}_30_${number}.log 2>&1 &
sleep 1.5
tail -n 1 log/run_${cc}_30_${number}.log
nohup ./waf --run "scratch/third input/config_${cc}_60.txt 60_${number}" > log/run_${cc}_60_${number}.log 2>&1 &
sleep 1.5
tail -n 1 log/run_${cc}_60_${number}.log
nohup ./waf --run "scratch/third input/config_${cc}_90.txt 90_${number}" > log/run_${cc}_90_${number}.log 2>&1 &
sleep 1.5
tail -n 1 log/run_${cc}_90_${number}.log

# 提示执行完成
echo "命令已执行，输出日志将被写入 log/run_${cc}_30_${number}.log, log/run_${cc}_60_${number}.log, 和 log/run_${cc}_90_${number}.log."
